// InputtingState.java
class InputtingState implements State {
    @Override
    public void onKeyPress(ControlPanel panel, char key) {
        panel.inputBuffer.append(key);
        System.out.println("输入：" + panel.getCurrentInput());

        // 如果输入达到4位，进行验证
        if (panel.getCurrentInput().length() == 4) {
            if (panel.isPasswordCorrect()) {
                System.out.println("密码正确！进入系统功能选择。");
                panel.setErrorCount(0);
                panel.setState(new SystemSelectState());
            } else {
                panel.setErrorCount(panel.getErrorCount() + 1);
                System.out.println("密码错误，当前错误次数：" + panel.getErrorCount());

                if (panel.getErrorCount() >= 3) {
                    System.out.println("错误3次以上，控制面板锁定！");
                    panel.setLockTime(LocalDateTime.now());
                    panel.setState(new LockedState());
                } else {
                    System.out.println("请重新输入密码...");
                    panel.clearInput(); // 清空输入
                }
            }
        }
    }
}